import java.io.IOException;
import java.io.PrintStream;
import java.net.Socket;
import java.net.UnknownHostException;


public class Cliente {
	
	public static void main( String[] args ) throws UnknownHostException, IOException {
		
		new Cliente( "127.0.0.1", Porta.porta, "Teste" ).executa();
	}
	
	private String host;
	private int porta;
	private MainFrame painel;
	private String usuario;
	
	public Cliente( final String host, final int porta, final String usuario ) {
		
		this.host = host;
		this.porta = porta;
		this.painel = new MainFrame();
		this.usuario = usuario;
	}
	
	public void executa() throws UnknownHostException, IOException {
		
		Socket cliente = new Socket( this.host, this.porta );
		System.out.println( "O cliente se conectou ao servidor!" );	
		
		PrintStream saida = new PrintStream( cliente.getOutputStream() );
		
		painel.mainFrame( usuario, saida, cliente );
		
		//Thread para receber mensagens do servidor 
		Recebedor recebedor = new Recebedor( cliente.getInputStream(), painel );
		
		new Thread( recebedor ).start();
		
		while( painel.getMainFrame().isEnabled() ) {			
			
		}		
		
		saida.close();
		cliente.close();
		

		
		
		
		
	}
}
